package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Rebate;
import com.ruoyi.system.service.IRebateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 返利记录表Controller
 * 
 * @author ruoyi
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/rebate")
@Slf4j
public class RebateController extends BaseController
{
    @Autowired
    private IRebateService rebateService;

    /**
     * 查询返利记录表列表
     */
    @RequiresPermissions("system:rebate:list")
    @GetMapping("/list")
    public TableDataInfo list(Rebate rebate)
    {
        //如果有推荐人，参考图4，插入一条用户返利记录（3分）
        //为了程序的性能，当购买完成服务器之后需要将相应用户的已购课程信息存入到缓存中，并且持久化到数据库中，已购服务器列表数据要求从Redis缓存中读取（5分）
        //3.6其他要求（5分）
        //注释合理（2分）
        //编码符合编码规范（3分）
        startPage();
        List<Rebate> list = rebateService.selectRebateList(rebate);
        return getDataTable(list);
    }

    /**
     * 导出返利记录表列表
     */
    @RequiresPermissions("system:rebate:export")
    @Log(title = "返利记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rebate rebate)
    {
        List<Rebate> list = rebateService.selectRebateList(rebate);
        ExcelUtil<Rebate> util = new ExcelUtil<Rebate>(Rebate.class);
        util.exportExcel(response, list, "返利记录表数据");
    }

    /**
     * 获取返利记录表详细信息
     */
    @RequiresPermissions("system:rebate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rebateService.selectRebateById(id));
    }

    /**
     * 新增返利记录表
     */
    @RequiresPermissions("system:rebate:add")
    @Log(title = "返利记录表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rebate rebate)
    {
        return toAjax(rebateService.insertRebate(rebate));
    }

    /**
     * 修改返利记录表
     */
    @RequiresPermissions("system:rebate:edit")
    @Log(title = "返利记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rebate rebate)
    {
        return toAjax(rebateService.updateRebate(rebate));
    }

    /**
     * 删除返利记录表
     */
    @RequiresPermissions("system:rebate:remove")
    @Log(title = "返利记录表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rebateService.deleteRebateByIds(ids));
    }
}
